package com.binarysoft.cmdhandler.common.memory;

import common.framework.command.handler.AbstractCommandHandler;
import common.framework.command.server.Terminal;
import common.framework.dsb.annotation.DSBCmd;

@DSBCmd("memory")
public class ShowMemoryCmdHandler extends AbstractCommandHandler {

	public void handle(String args, Terminal terminal) throws Exception {
		terminal.println("");
		long totalMemory = Runtime.getRuntime().totalMemory();
		long freeMemory = Runtime.getRuntime().freeMemory();
		double free = (freeMemory / 1024) / 1024;
		double total = (totalMemory / 1024) / 1024;
		terminal.println("  Free  memory: " + freeMemory + " bytes (" + free + " MBytes).");
		terminal.println("  Total memory: " + totalMemory + " bytes (" + total + " MBytes).");
		double usage = 1 - ((double) freeMemory / (double) totalMemory);
		terminal.println("  Memory usage: " + ((int) (usage * 100)) + "%");
		terminal.println("");
	}
}
